package com.financing.platform.dao.impl;


import java.sql.SQLException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IFaUserDao;
import com.financing.platform.dto.FaUserDTO;
import com.financing.platform.util.SqlName;
import com.financing.platform.util.StringUtil;
import com.financing.platform.vo.EmailTemplateUserVO;
import com.financing.platform.vo.FaUserVO;

@Repository("faUserDaoImpl")
public class FaUserDaoImpl extends BaseDaoImpl  implements IFaUserDao {

	@SuppressWarnings("unchecked")
	public List<FaUserDTO> getFaUserList(FaUserDTO faUserDTO) {
		try {
			return (List<FaUserDTO>)this.sqlMapClient.queryForList(SqlName.queryAllFaUser,faUserDTO);
		} catch (SQLException e) {
			log.error("Query Fa user error:",e);
			return Collections.emptyList();
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<FaUserDTO> getShopFaUserList(FaUserDTO faUserDTO) {
		try {
			return (List<FaUserDTO>)this.sqlMapClient.queryForList(SqlName.queryAllShopFaUser,faUserDTO);
		} catch (SQLException e) {
			log.error("Query Fa user error:",e);
			return Collections.emptyList();
		}
	}

	public int updateFaUserInfo(FaUserDTO faUserDTO) {
		try {
			return this.sqlMapClient.update(SqlName.updateFaUserInfo, faUserDTO);
		} catch (SQLException e) {
			log.error("Update fa user info error:",e);
			return 0;
		}
	}

	public FaUserDTO getFaUser(FaUserDTO fauserDTO) {
		try {
			return (FaUserDTO) this.sqlMapClient.queryForObject(SqlName.queryAllFaUser, fauserDTO);
		} catch (SQLException e) {
			log.error("Query Fa user error:",e);
			return fauserDTO;
		}
	}
	@Override
	public FaUserDTO getFaUserView(FaUserDTO fauserDTO) throws SQLException{
		return (FaUserDTO) this.sqlMapClient.queryForObject(SqlName.queryFaUserView, fauserDTO);
	}
	@SuppressWarnings("unchecked")
	public List<Integer> getAllFaId(Integer corpId) {
		try {
			return this.sqlMapClient.queryForList(SqlName.queryFaAllId,corpId);
		} catch (SQLException e) {
			log.error("Query all fa id error:",e);
			return Collections.emptyList();
		}
	}

	@Override
	public int getFaUserListCount(FaUserDTO faUserDTO) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.queryAllFaUserCount, faUserDTO);
	}
	
	@Override
	public int getShopFaUserListCount(FaUserDTO faUserDTO) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.queryAllShopFaUserCount, faUserDTO);
	}
	
	@Override
	public int updateFaUserStatus(FaUserDTO faUserDTO) throws SQLException {
		return this.sqlMapClient.update(SqlName.updateFaUserStatus, faUserDTO);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<FaUserVO> queryFaUserListAuthPass(FaUserDTO faUserDTO) throws SQLException {
		return (List<FaUserVO>)this.sqlMapClient.queryForList(SqlName.queryFaUserListAuthPass,faUserDTO);
	}

	@Override
	public int queryFaUserListAuthPassCount(FaUserDTO faUserDTO)
			throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.queryFaUserListAuthPassCount, faUserDTO);
	}

	@Override
	public int querySingleFaUserListAuthPassCount(FaUserDTO faUserDTO) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.querySingleFaUserListAuthPassCount, faUserDTO);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<FaUserDTO> querySingleFaUserListAuthPass(FaUserDTO faUserDTO)
			throws SQLException {
		return (List<FaUserDTO>)this.sqlMapClient.queryForList(SqlName.querySingleFaUserListAuthPass,faUserDTO);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<EmailTemplateUserVO> queryFaUserVerify() throws SQLException {
		return (List<EmailTemplateUserVO>)this.sqlMapClient.queryForList(SqlName.queryFaUserVerify);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<String> queryFaUserVPassEmail(Map<String, Integer> param)
			throws SQLException {
		return this.sqlMapClient.queryForList(SqlName.queryFaUserVPassEmail,param);
	}

	@Override
	public int updateFaUserInfoForMap(Map<String, Object> map)
			throws SQLException {
		return this.sqlMapClient.update(SqlName.updateFaUserInfoForMap, map);
	}

	@Override
	public Integer getFaUserOrderCount(String userId) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject(SqlName.getFaUserOrderCount, userId);
	}

	@Override
	public List<String> queryFaUserSubUserId(Map<String, String> param) throws SQLException{
		return this.sqlMapClient.queryForList(SqlName.queryFaUserSubUserId,param);
	}

	@Override
	public List<String> queryActSource() throws SQLException {
		return this.sqlMapClient.queryForList("faUser.queryActSource");
	}

	@Override
	public List<FaUserDTO> queryAllFaUserInfoBasic(FaUserDTO faUserDTO) throws SQLException {
		//id to String ids
		faUserDTO.setLicaishiIds(StringUtil.splitToIn(faUserDTO.getLicaishiIds()));
		return (List<FaUserDTO>)this.sqlMapClient.queryForList("faUser.queryAllFaUserInfoBasic",faUserDTO);
	}

	@Override
	public String queryFrontLicaishiManagerUser(String id) throws SQLException {
		return (String) this.sqlMapClient.queryForObject("faUser.queryFrontLicaishiManagerUser", id);
	}

	@Override
	public int queryAllFaUserSystemRateCount(FaUserDTO faUserDTO) throws SQLException {
		return (Integer) this.sqlMapClient.queryForObject("faUser.queryAllFaUserSystemRateCount",faUserDTO );
	}

	@Override
	public List<FaUserDTO> queryAllFaUserSystemRate(FaUserDTO faUserDTO) throws SQLException {
		return (List<FaUserDTO>)this.sqlMapClient.queryForList("faUser.queryAllFaUserSystemRate",faUserDTO);
	}

	@Override
	public void updateFaUserSystemRate(FaUserDTO faUserDTO) throws SQLException {
		this.sqlMapClient.update("faUser.updateFaUserSystemRate",faUserDTO);
	}

	@Override
	public List<FaUserDTO> queryFaUserNomanager(String date) throws SQLException {
		return (List<FaUserDTO>)this.sqlMapClient.queryForList("faUser.queryFaUserNomanager",date);
	}
}